#ifndef CPARTICLEEMITTER_H_
#define CPARTICLEEMITTER_H_

#include "../SGD Wrappers/CSGD_Direct3D.h"
#include "../SGD Wrappers/CSGD_TextureManager.h"
#include "../SGD Wrappers/SGD_Math.h"


#include <vector>
using namespace std;
#include <string>

class CParticleEmitter
{
	struct Particle
	{
		float lifeTime;
		void SetLifeTime(float _lifeTime)
		{
			lifeTime = _lifeTime;
		}
		float GetLifeTime()
		{
			return lifeTime;
		}

		float posX;
		void SetPosX(float _posX)
		{
			posX = _posX;
		}
		float GetPosX()
		{
			return posX;
		}

		float posY;
		void SetPosY(float _posY)
		{
			posY = _posY;;
		}
		float GetPosY()
		{
			return posY;
		}

		float velX;
		void SetVelX(float _velX)
		{
			velX = _velX;
		}
		float GetVelX()
		{
			return velX;
		}

		float velY;
		void SetVelY(float _velY)
		{
			velY = _velY;
		}
		float GetVelY()
		{
			return velY;
		}

		float scale;
		void SetScale(float _scale)
		{
			scale = _scale;
		}
		float GetScale()
		{
			return scale;
		}

		D3DCOLOR color;

		Particle(float _startPosX, float _startPosY, float _startVelX, float _startVelY, float _startScale, D3DCOLOR _startColor, float _lifeTime)
		{
			this->posX = _startPosX;
			this->posY = _startPosY;
			this->velX = _startVelX;
			this->velY = _startVelY;
			this->scale = _startScale;
			this->color = _startColor;
			this->lifeTime = _lifeTime;
		}

		void Update(float _elapsedTime)
		{
			lifeTime -= _elapsedTime;
			posX = posX + (velX*_elapsedTime);
			posY = posY + (velY*_elapsedTime);
		}

		void Render(int _imageid)
		{
			//scale = 0.01f;
			CSGD_TextureManager::GetInstance()->Draw(_imageid, (int)posX - ((int)(4*scale)), (int)posY - ((int)(4*scale)), scale, scale, NULL, 0, 0, 0, color);
		}
	};

	vector<Particle*> aliveParticles;
	vector<Particle*> deadParticles;

	int imageId;
	string name;

	float lifeTime;
	float timer;
	float burstTimer;
	float originalBurstTime;
	float waitTimer;

	int numberOfParticles;

	int particleRate;

	float startPosX;
	float startPosY;
	float startVelX;
	float startVelY;
	float startScale;
	D3DCOLOR startColor;
	unsigned char startColorData[4];

	float ratePosX;
	float ratePosY;
	float rateVelX;
	float rateVelY;
	float rateScale;
	float rateColor[4];

	float randomAngle;
	Vector2D randomVelocity;

	int emitterRectWidth;
	int emitterRectHeight;

	int sourceBlend;
	int destinationBlend;

	bool isLooping;

	bool titleState;

	bool active;

public:
	void SetEmitterStartVelocityX(float value)
	{
		startVelX = value;
	}

	void SetEmitterStartVelocityY(float value)
	{
		startVelY = value;
	}

	float GetEmitterStartVelocityX()
	{
		return startPosX;
	}

	float GetEmitterStartVelocityY()
	{
		return startPosY;
	}

	void SetEmitterStartPositionX(float value)
	{
		startPosX = value;
	}

	void SetEmitterStartPositionY(float value)
	{
		startPosY = value;
	}

	void SetActive(bool value)
	{
		active = value;
	}

	void SetLooping(bool value)
	{
		isLooping = value;
	}

	void SetColor(D3DCOLOR color)
	{
		startColor = color;
	}

	void SetTitleState(bool value)
	{
		titleState = value;
	}

	float GetEmitterStartPositionX()
	{
		return startVelX;
	}

	float GetEmitterStartPositionY()
	{
		return startVelY;
	}

	float GetBurstTimer()
	{
		return burstTimer;
	}

	bool GetActive()
	{
		return active;
	}

	CParticleEmitter(void);
	~CParticleEmitter(void);

	void Load(const char* filename, int imageid);
	void XMLLoad(const char* filename, int imageid);
	
	void UnLoad();

	void CopyMeTo(CParticleEmitter* newparticle);

	void Update(float gametime);

	void Render();
};


#endif